<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>注册页面</title>
    <style>
        li {
            list-style: none;
            margin-top: 15px;
        }
    </style>
</head>

<body>
    <ul>
        <h2>注册界面</h2>
        <li>注册一个帐号</li>
        <form id="register_form">
            <li>
                <label for="">用户昵称</label>
                <input type="text" name="nickname" id="">

            </li>
            <li>
                <label for="">手机号码</label>
                <input type="text" name="phone" id="">
            </li>
            <li>
                <label for="">登陆密码</label>
                <input type="password" name="password" id="">
            </li>
            <li>
                <label for="">重复密码</label>
                <input type="password" name="password_2" id="">
            </li>
            <li>
                <input type="checkbox" name="" id="checkbox">
                <label for="">我同意</label>
                <a href="">相关同意条款</a>
            </li>
            <li>
                <input type="submit" name="" id="register" value="注册>">
            </li>
        </form>
    </ul>
    <script src="__STATIC__/js/jquery-3.4.1.js"></script>
    <script>
        $(function() {
            $('#register').attr('disabled', 'disabled'); //禁用注册按钮
            $('#checkbox').on('click', function() { //给复选框绑定事件
                if ($(this).prop('checked')) { //如果被选中
                    //解除注册按钮的禁用
                    $('#register').removeAttr('disabled');
                } else { //没有被选中，就禁用注册按钮
                    $('#register').attr('disabled', 'disabled'); //禁用注册按钮
                }
            });
            $('#register').on('click', function(e) { //为注册按钮绑定单击事件
                e.preventDefault(); //禁止注册按钮的冒泡事件
                $.ajax({ //利用ajax传输数据
                    type: 'POST',
                    url: "{:url('register_do','','')}",
                    data: $('#register_form').serialize(),
                    success: function(result) {
                        //判断后台传回来的数据
                        if (result.code == 1) {
                            alert(result.msg);
                            $(location).attr("href", "{:url('login','','')}");
                        } else {
                            alert(result.msg);
                        }
                    }
                })
            })
        });
    </script>
</body>

</html>